package assignmentImplementation;



import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import keyValueBaseInterfaces.Key;

@XmlRootElement(name="keyimpl")
public class KeyImpl implements Key<KeyImpl>
{

	@XmlElement(name="keydata")
	private int key;
	
	public KeyImpl(){
		key = -1;
	}
	
	public KeyImpl(int aVal){
		this.key = aVal;
	}
	

	public int compareTo(KeyImpl arg0) {
		if(this.key == arg0.key)
			return 0; //Equal
		else if (this.key > arg0.key)
			return 1; //Greater then
		else
			return -1; //Less then
	}
	
	public String toString() {
		String s = String.valueOf(this.key);
		return s;
	}

	public int getKey(){
		return this.key;
	}
	
	// information on overloading equals found on this site:
	// http://javarevisited.blogspot.dk/2011/02/how-to-write-equals-method-in-java.html
	
	public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (o == null || o.getClass() != this.getClass()) {
            return false;
        }

        KeyImpl aKey = (KeyImpl) o;
        	return this.key == aKey.key;
        }
	
	public int hashCode(){
		return this.toString().hashCode();
	}
}
